package de.playmee;

import de.playmee.dialogs.CustomDialog;
import de.playmee.handler.MusicHandler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public abstract class MainMenuActivity extends Activity {

	/**
	 * called when the options menu is first created
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return true;
	}
	
	/**
	 * called once the menu is selected
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent i = null;
		Playmee application = (Playmee) getApplication();
		
		switch (item.getItemId()) {
		// decide which menu option is selected
		case R.id.region:
			application.currentRegion = null;
			application.isStartingChannelInRegion = false;
			break;
		case R.id.library:
			MusicHandler mHandler = application.getMusicHandler();
			if (mHandler.getCheckCount() == 0) {
				i = new Intent(getApplicationContext(), LibraryActivity.class);
			} else {
				CustomDialog.showInfoDialog(this, "Caution",
						"Please wait until downloading the music data is done.");
			}
			break;
		case R.id.preferences:
			i = new Intent(getApplicationContext(), PreferencesActivity.class);
			break;
		}
		if (i != null)
			startActivity(i);
		return true;
	}
}
